package com.yunshang.ys.base;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yunshang.ys.R;
import com.yunshang.ys.ys.YSFragment;

//import com.risenbsy.ixing.R;
//import com.risenbsy.risenbsylib.base.RisFragment;

//import com.risenb.yiweather.R;

/**
 * Created by Administrator on 2016/11/3.
 */

public class BaseFragment extends YSFragment {

    private boolean isTitleShow = false;

    /**
     * 显示标题
     */
    public BaseFragment showTitle(String text) {
        if(getView().findViewById(R.id.titleBar)==null) return this;
        getView().findViewById(R.id.titleBar).setVisibility(View.VISIBLE);
        TextView title = (TextView) getView().findViewById(R.id.title);
        title.setVisibility(View.VISIBLE);
        title.setText(text);
        isTitleShow = true;
        return this;
    }
    //标题增加图标
    public BaseFragment showTitleImage(int imageId) {
        if(!isTitleShow)return  this;
        TextView title = (TextView) getView().findViewById(R.id.title);
        Drawable img = getContext().getResources().getDrawable(imageId,null);
        img.setBounds(0,0,img.getMinimumWidth(),img.getMinimumHeight());
        title.setCompoundDrawablePadding(14);
        title.setCompoundDrawables(img,null,null,null);
        return this;
    }
    //标题增加监听
    public BaseFragment setTitleOnClick(View.OnClickListener onClickListener){
        getView().findViewById(R.id.title).setOnClickListener(onClickListener);
        return this;
    }

    public BaseFragment setBackground(int color){
        if(!isTitleShow)return  this;
        getView().findViewById(R.id.titleBar).setBackgroundColor(color);
        return this;
    }
    /**
     * 显示返回
     */
    public BaseFragment withBack() {
        if (!isTitleShow) return this;
        RelativeLayout back = (RelativeLayout) getView().findViewById(R.id.back);
        back.setVisibility(View.VISIBLE);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getActivity().finish();
            }
        });
        return this;
    }

    /**
     * 显示右边文字
     */
    public BaseFragment withRightText(String text, View.OnClickListener onClickListener) {
        if (!isTitleShow) return this;
        TextView rightText = (TextView) getView().findViewById(R.id.rightText);
        rightText.setVisibility(View.VISIBLE);
        rightText.setText(text);
        rightText.setOnClickListener(onClickListener);
        return this;
    }

    /**
     * 显示右边按钮1
     */
    public BaseFragment withRightBtn1(int image, View.OnClickListener onClickListener) {
        if (!isTitleShow) return this;
        ImageView rightBtn1 = (ImageView) getView().findViewById(R.id.rightIcon1);
        rightBtn1.setVisibility(View.VISIBLE);
        rightBtn1.setImageResource(image);
        rightBtn1.setOnClickListener(onClickListener);
        return this;
    }

    /**
     * 显示右边按钮2
     */
    public BaseFragment withRightBtn2(int image, View.OnClickListener onClickListener) {
        if (!isTitleShow) return this;
        ImageView rightBtn2 = (ImageView) getView().findViewById(R.id.rightIcon2);
        rightBtn2.setVisibility(View.VISIBLE);
        rightBtn2.setImageResource(image);
        rightBtn2.setOnClickListener(onClickListener);
        return this;
    }

     // 显示左边按钮图片
    public BaseFragment setLiftIamge(int image) {
        if (!isTitleShow) return this;
        ImageView imageView = (ImageView) getView().findViewById(R.id.leftImage);
        imageView.setImageResource(image);
        return this;
    }
    //设置左边文字
    public BaseFragment setLiftText(String text){
        if(!isTitleShow) return this;
        TextView textView = (TextView) getView().findViewById(R.id.leftText);
        textView.setText(text);
        return this;
    }
    //注册监听左侧文字
    public BaseFragment setLiftTextOnClick(View.OnClickListener onClickListener){
        getView().findViewById(R.id.leftBt).setOnClickListener(onClickListener);
        return this;
    }
    public View getTitleView(){
        return  getView().findViewById(R.id.titleBar) ;
    }


//    @Override
//    public void showProgressDialog(String message, boolean cancelAble) {
//        try {
//            SingleProgressDialog.getInstance(getAppContext(),false).show();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }

//    @Override
//    public void dismissProgressDialog() {
//        try {
//            SingleProgressDialog.getInstance(getAppContext(),false).dismiss();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }


//    @Override
//    public void onDestroy() {
//        super.onDestroy();
//        SingleProgressDialog.makenull();
//    }
}
